"""
短信模版设置页面类
"""
from ..base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

class SetSendEmailPage(BasePage):
    #数据
    url="/crm/index.php?m=email&a=index"
    #定位器
    addmodel_locator = (By.ID, "add")
    namemodel_locator = (By.CSS_SELECTOR, "#dialog-add > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > input")
    title_locator = (By.CLASS_NAME, "span4")
    text_locator = (By.NAME, "content")
    btn_locator = (By.NAME, "submit")
    tips_success_locator = (By.XPATH, "/ html / body / div[5] / div[2]")
    del_email_model_locator = (By.CSS_SELECTOR, "#btn_delete")
    select_emil_locator = (By.CSS_SELECTOR, "#form1 > div:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    tips_del_success_locator = (By.XPATH, "/ html / body / div[5] / div[2]")


    #方法
    def addmodel(self):
        self.click(self.addmodel_locator)
    def name(self,name):
        self.send_keys(self.namemodel_locator,name)
    def title(self,title):
        self.send_keys(self.title_locator,title)
    def text(self,content):
        self.send_keys(self.text_locator,content)
    def btn_save(self):
        self.click(self.btn_locator)
    def del_email_model(self):
        """点击删除并确认弹窗"""
        self.click(self.del_email_model_locator)
        # 等待 confirm 出现并点“确定”
        WebDriverWait(self.driver, 8).until(EC.alert_is_present()).accept()
    def select_emil(self):
        self.click(self.del_email_model_locator)
    def tips_success(self):  #邮件模版设置成功断言
        return self.find_element(self.tips_success_locator).text
    def tips_del_success(self):  #邮件模版删除成功断言
        return self.find_element(self.tips_del_success_locator).text
